package com.liu.resume.viewmodel;


import com.liu.resume.model.UserModel;

import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

/**
 * Created by Administrator on 2016/7/27.
 */
public class QueryAvatarViewModel {
    Listener listener;

    public QueryAvatarViewModel(Listener listener) {
        this.listener = listener;
    }

    public void getAvatar(String username) {
        BmobQuery<UserModel> query = new BmobQuery<>();
        query.addWhereEqualTo("username", username);
        query.findObjects(new FindListener<UserModel>() {
            @Override
            public void done(List<UserModel> list, BmobException e) {
                if (e == null) {
                    listener.onAvatarSuccess(list.get(0).getAvatar());
                } else {
                    listener.onAvatarFail();
                }
            }
        });

    }

    public interface Listener {

        void onAvatarSuccess(String imgUrl);


        void onAvatarFail();


    }
}
